﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using System.IO;

namespace DARE
{
    public enum EEffectOption : uint
    {
        NONE = 0,
        BUMP = 1,
        SPECULAIRE = 2,
        REFLECTION = 4,
        ANIMATION = 8,
        FOG = 16,
        TRANSPARENCY = 32,
    }

    public static class CEffectBank
    {
        #region Const

        private const string _FXEXTENTION = ".fx";

        #endregion

        #region Fields

        private static Dictionary<uint, CBasicEffect> m_effects;
        private static CBasicEffect m_current;
        private static CCamera m_currentCamera;
        private static uint m_currentId;
        private static uint m_idCount = 0;

        #endregion

        #region Property

        public static CBasicEffect CurrentEffect
        {
            get
            {
                if (m_current == null)
                    return null;
                return m_current;
            }
        }

        public static uint CurrentEffectId
        {
            get { return m_currentId; }
        }

        #endregion

        #region CTOR

        static CEffectBank()
        {
            m_effects = new Dictionary<uint, CBasicEffect>();
        }

        #endregion

        #region Method

        public static bool SetCurrentEffectById(uint _effectId)
        {
            if (!m_effects.ContainsKey(_effectId))
                return false;
            if (m_current == m_effects[_effectId])
                return true;
            m_current = m_effects[_effectId];

            m_currentId = _effectId;


            return true;
        }

        public static void SetCurrentCamera(CRender3D _scene)
        {
            m_currentCamera = _scene.CameraMgr.ActiveCamera;
        }

        internal static uint RegisterShader(CBasicEffect cbe)
        {
            var id = (from el in m_effects
             where el.Value.Name == cbe.Name
             select el.Key);
            if (id.Count() == 1)
                return id.First();
            m_effects.Add(m_idCount, cbe);
            return m_idCount++;
        }


        #endregion
    }
}
